package ch.ethz.fcl.metrobuzz.algorithm.network.shortest_path.general;

import java.util.HashMap;
import java.util.Map;

import ch.ethz.fcl.metrobuzz.algorithm.network.Path;
import ch.ethz.fcl.metrobuzz.data.MBData;
import ch.ethz.fcl.metrobuzz.data.scene.basemap.Node;

public class AllToAllDijkstra {
	private MBData data;

	private OneToAllDijkstra dijkstra;

	// key: source node
	// value key: destination node
	// value value: source to destination path
	private Map<Node, Map<Node, Path>> nodeToNodePathMap;

	public AllToAllDijkstra(MBData data) {
		this.data = data;
		this.dijkstra = new OneToAllDijkstra(this.data);
		nodeToNodePathMap = new HashMap<Node, Map<Node, Path>>();
	}

	public Path getPath(Node source, Node end) {
		Map<Node, Path> sourcePathMap = nodeToNodePathMap.get(source);

		if (sourcePathMap == null) {
			sourcePathMap = dijkstra.getShortestPath(source);
			// System.out.println(source.getId()+" path map size "+sourcePathMap.size());
			nodeToNodePathMap.put(source, sourcePathMap);
		}

		return sourcePathMap.get(end);
	}
}
